using System;
using System.Globalization;
using System.IO.Ports;
using System.Windows;
using System.Windows.Data;

namespace SerialPortCommunicationProject
{
    [ValueConversion(typeof(Parity), typeof(string))]
    public class ParityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Parity re = (Parity)value;
            switch (re)
            {
                case Parity.None:
                    return "None";
                case Parity.Odd:
                    return "Odd";
                case Parity.Even:
                    return "Even";
                case Parity.Mark:
                    return "Mark";
                case Parity.Space:
                    return "Space";
                default:
                    return "请选择";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value as string;
            switch (strValue)
            {
                case "None":
                    return Parity.None;
                case "Odd":
                    return Parity.Odd;
                case "Even":
                    return Parity.Even;
                case "Mark":
                    return Parity.Mark;
                case "Space":
                    return Parity.Space;
            }
            return DependencyProperty.UnsetValue;
        }
    }
}

    
